package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.MarketOrderGoods;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.bo.WxOrderCommentBO;
import com.cskaoyan.bean.bo.WxOrderListBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.SimpleRespVO;
import com.cskaoyan.bean.vo.WxOrderDetailVO;
import com.cskaoyan.bean.vo.WxOrderListVO;
import com.cskaoyan.bean.vo.WxOrderSubmitVo;
import com.cskaoyan.service.wx.WxOrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//import javax.security.auth.Subject;
import java.util.Map;

/**
 * @author : gao
 * @since: 2022/10/14  14:26
 */
@RestController
@RequestMapping("wx/order")
public class WXOrderController {

    @Autowired
    WxOrderService wxOrderService;

    @RequestMapping("list")
    public BaseRespVo<CommonData> list(WxOrderListBO wxOrderListBO) {
        CommonData<WxOrderListVO> data = wxOrderService.list(wxOrderListBO);
        return BaseRespVo.ok(data, "成功");
    }

    @GetMapping("detail")
    public BaseRespVo<WxOrderDetailVO> detail(Integer orderId) {
        WxOrderDetailVO orderDetailVO = wxOrderService.detail(orderId);
        return BaseRespVo.ok(orderDetailVO, "成功");
    }

    @PostMapping("refund")
    public BaseRespVo refund(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.refund(orderId);
        return BaseRespVo.ok("成功");
    }

    @PostMapping("confirm")
    public BaseRespVo confirm(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.confirm(orderId);
        return BaseRespVo.ok("成功");
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.delete(orderId);
        return BaseRespVo.ok("成功");
    }

    @PostMapping("cancel")
    public BaseRespVo cancel(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.cancel(orderId);
        return BaseRespVo.ok("成功");
    }

    @RequestMapping("goods")
    public BaseRespVo<MarketOrderGoods> goods(Integer orderId, Integer goodsId) {
        MarketOrderGoods marketOrderGoods = wxOrderService.goods(orderId, goodsId);
        return BaseRespVo.ok(marketOrderGoods, "成功");
    }

    @PostMapping("comment")
    public BaseRespVo comment(@RequestBody WxOrderCommentBO wxOrderCommentBO) {
        Subject subject = SecurityUtils.getSubject();
        PrincipalCollection principals = subject.getPrincipals();
        MarketUser user = (MarketUser) principals.getPrimaryPrincipal();

        Integer userId = user.getId();
        wxOrderService.comment(userId, wxOrderCommentBO);
        return BaseRespVo.ok("成功");

    }

    @PostMapping("submit")
    public BaseRespVo submit(@RequestBody Map map) {

        WxOrderSubmitVo wxOrderSubmitvo = wxOrderService.submit(map);
        return BaseRespVo.ok(wxOrderSubmitvo, "成功");
    }


    @PostMapping("prepay")
    public BaseRespVo prepay(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.prepay(orderId);
        return BaseRespVo.ok("成功");
    }


}
